//
//  SISSCommonSingleSignView.m
//  SISSAPP
//
//  Created by 袁应荣 on 2017/9/21.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSCommonSingleSignView.h"
#import <SDWebImage/UIImageView+WebCache.h>

@interface SISSCommonSingleSignView ()

/* 甲方Label */
@property (weak, nonatomic) UILabel *firstPartyLabel;
/* 乙方Label */
@property (weak, nonatomic) UILabel *secondPartyLabel;
/* 甲方签署日期Label */
@property (weak, nonatomic) UILabel *firstPartySignLabel;
/* 乙方方签署日期Label */
@property (weak, nonatomic) UILabel *secondPartySignLabel;

/// 甲方名字Label
@property (weak, nonatomic) UILabel *firstPartyNameLabel;
/// 乙方名字Label
@property (weak, nonatomic) UILabel *secondPartyNameLabel;
/// 甲方签字imageView
@property (weak, nonatomic) UIImageView *firstPartyImageView;
/// 乙方方签字imageView
@property (weak, nonatomic) UIImageView *secondPartyImageView;
/// 甲方签署日期Label
@property (weak, nonatomic) UILabel *firstPartySignTimeLabel;
/// 乙方签署日期Label
@property (weak, nonatomic) UILabel *secondPartySignTimeLabel;

@end
@implementation SISSCommonSingleSignView

- (void)setFirstPartyName:(NSString *)firstPartyName {
    _firstPartyName = firstPartyName;
    self.firstPartyNameLabel.text = firstPartyName;
}

- (void)setSecondPartyName:(NSString *)secondPartyName {
    _secondPartyName = secondPartyName;
    self.secondPartyNameLabel.text = secondPartyName;
}

- (void)setFirstPartyImageUrlStr:(NSString *)firstPartyImageUrlStr {
    _firstPartyImageUrlStr = firstPartyImageUrlStr;
    [self.firstPartyImageView sd_setImageWithURL:[NSURL URLWithString:firstPartyImageUrlStr]];
}

- (void)setSecondPartyImageUrlStr:(NSString *)secondPartyImageUrlStr {
    _secondPartyImageUrlStr = secondPartyImageUrlStr;
    [self.secondPartyImageView sd_setImageWithURL:[NSURL URLWithString:secondPartyImageUrlStr]];
}

- (void)setSignImage:(UIImage *)signImage {
    _signImage = signImage;
    self.secondPartyImageView.image = signImage;
}

- (void)setFirstPartySignTime:(NSString *)firstPartySignTime {
    _firstPartySignTime = firstPartySignTime;
    self.firstPartySignTimeLabel.text = firstPartySignTime;
}

- (void)setSecondPartySignTime:(NSString *)secondPartySignTime {
    _secondPartySignTime = secondPartySignTime;
    self.secondPartySignTimeLabel.text = secondPartySignTime;
}

#pragma mark - UI
- (void)initUI {
    [super initUI];
    
    // 甲方
    UILabel *firstPartyLabel = [UILabel yyr_labelWithText:@"【甲方】：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:firstPartyLabel];
    self.firstPartyLabel = firstPartyLabel;
    
    UILabel *firstPartyNameLabel = [UILabel yyr_labelWithText:@" " fontSize:16 textColor:MAIN_TEXT_COLOR];
    firstPartyNameLabel.numberOfLines = 0;
    firstPartyNameLabel.font = [UIFont boldSystemFontOfSize:16];
    firstPartyNameLabel.text = @" ";
    [self addSubview:firstPartyNameLabel];
    self.firstPartyNameLabel = firstPartyNameLabel;
    
    // 甲方签名
    UIImageView *firstPartyImageView = [[UIImageView alloc] init];
    firstPartyImageView.backgroundColor = COLOR(0xD2E0EB);
    [self addSubview:firstPartyImageView];
    self.firstPartyImageView = firstPartyImageView;
    
    // 甲方签署日期
    UILabel *firstPartySignLabel = [UILabel yyr_labelWithText:@"签署日期：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:firstPartySignLabel];
    self.firstPartySignLabel = firstPartySignLabel;
    
    // 乙方
    UILabel *secondPartyLabel = [UILabel yyr_labelWithText:@"【乙方】：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:secondPartyLabel];
    self.secondPartyLabel = secondPartyLabel;
    
    UILabel *secondPartyNameLabel = [UILabel yyr_labelWithText:@" " fontSize:16 textColor:MAIN_TEXT_COLOR];
    secondPartyNameLabel.numberOfLines = 0;
    secondPartyNameLabel.font = [UIFont boldSystemFontOfSize:16];
    [self addSubview:secondPartyNameLabel];
    self.secondPartyNameLabel = secondPartyNameLabel;

    // 乙方签名
    UIImageView *secondPartyImageView = [[UIImageView alloc] init];
    secondPartyImageView.backgroundColor = COLOR(0xD2E0EB);
    [self addSubview:secondPartyImageView];
    self.secondPartyImageView = secondPartyImageView;
    
    UILabel *firstPartySignTimeLabel = [UILabel yyr_labelWithText:@"签署日期：" fontSize:16 textColor:MAIN_TEXT_COLOR];
    firstPartySignTimeLabel.font = [UIFont boldSystemFontOfSize:16];
    [self addSubview:firstPartySignTimeLabel];
    self.firstPartySignTimeLabel = firstPartySignTimeLabel;
    // 乙方签署日期
    UILabel *secondPartySignLabel = [UILabel yyr_labelWithText:@"签署日期：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:secondPartySignLabel];
    self.secondPartySignLabel = secondPartySignLabel;
    
    UILabel *secondPartySignTimeLabel = [UILabel yyr_labelWithText:@"签署日期：" fontSize:16 textColor:MAIN_TEXT_COLOR];
    secondPartySignTimeLabel.font = [UIFont boldSystemFontOfSize:16];
    [self addSubview:secondPartySignTimeLabel];
    self.secondPartySignTimeLabel = secondPartySignTimeLabel;
    
}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    WeakSelf
    CGFloat margin = 8.0;
    CGSize signImageSize = CGSizeMake(([SISSPublicSingleton shared].screenWidth - 32) * 0.5, ([SISSPublicSingleton shared].screenWidth - 64) * 0.4);
    // 甲方
    [self.firstPartyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf).offset(margin);
        make.left.equalTo(weakSelf).offset(margin);
    }];
    [self.firstPartyNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.firstPartyLabel.mas_right);
        make.top.equalTo(weakSelf.firstPartyLabel);
    }];
    
    // 甲方签名
    [self.firstPartyImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.firstPartyLabel);
        make.top.equalTo(weakSelf.firstPartyLabel.mas_bottom).offset(margin);
        make.size.mas_equalTo(signImageSize);
    }];
    // 甲方签署日期
    [self.firstPartySignLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.firstPartyImageView);
        make.top.equalTo(weakSelf.firstPartyImageView.mas_bottom).offset(margin);
    }];
    [self.firstPartySignTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        if (SCREEN_WIDTH < 375) {
            make.left.equalTo(weakSelf.firstPartySignLabel);
            make.top.equalTo(weakSelf.firstPartySignLabel.mas_bottom).offset(margin);
        } else {
            make.left.equalTo(weakSelf.firstPartySignLabel.mas_right);
            make.centerY.equalTo(weakSelf.firstPartySignLabel);
        }
    }];
    // 乙方
    [self.secondPartyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.firstPartyLabel);
        make.left.equalTo(weakSelf.secondPartyImageView);
    }];
    [self.secondPartyNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.secondPartyLabel.mas_right);
//        make.right.equalTo(weakSelf).offset(-2 * margin).priority(999);
        make.top.equalTo(weakSelf.secondPartyLabel);
    }];

    // 乙方签名
    [self.secondPartyImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.firstPartyImageView);
        make.right.equalTo(weakSelf).offset(-margin);
        make.size.mas_equalTo(signImageSize);
    }];
    
    // 乙方签署日期
    [self.secondPartySignLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.secondPartyImageView);
        make.top.equalTo(weakSelf.secondPartyImageView.mas_bottom).offset(margin);
        make.bottom.equalTo(weakSelf).offset(-margin);
    }];
    [self.secondPartySignTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        if (SCREEN_WIDTH < 375) {
            make.left.equalTo(weakSelf.secondPartySignLabel);
            make.top.equalTo(weakSelf.secondPartySignLabel.mas_bottom).offset(margin);
        } else {
            make.left.equalTo(weakSelf.secondPartySignLabel.mas_right);
            make.centerY.equalTo(weakSelf.secondPartySignLabel);
        }
    }];
}

@end
